package control;

import java.io.IOException;
import java.util.ArrayList;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import business.HolidayManager;
import model.HolidayDTO;

public class LoadHolidayServlet extends HttpServlet {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public LoadHolidayServlet()
	{
		super();
	}
	
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);
	}
	
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);
	}
	private void processRequest(HttpServletRequest request,
			HttpServletResponse response) {
		HolidayManager hm = new HolidayManager ();
		ArrayList<HolidayDTO> data = hm.findAllHoliday();
		request.setAttribute("holidays", data);
		RequestDispatcher rd = request.getRequestDispatcher("/LoadHoliday.jsp");
		try{
			rd.forward(request, response);
		}catch (ServletException e) {
			// TODO: handle exception
			e.printStackTrace();
		}catch (IOException e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}
}
